﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using UygulamaYetkiService.Classes;

namespace UygulamaYetkiService
{
    public class IletisimDao : IDisposable
    {
        public Iletisim IletisimGetir()
        {
            Iletisim iletisim = null;
            try
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguYetkiConnection"].ToString()))
                {
                    string sql = string.Format(@"select ID,Adres,Telefon,Fax,Mail,TelefonGsm from Iletisim with(nolock)");
                    using (SqlCommand cmd = new SqlCommand(sql))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            cmd.Connection = con;
                            sda.SelectCommand = cmd;
                            cmd.CommandTimeout = 60000;
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            if (dt.Rows.Count > 0)
                            {
                                foreach (DataRow dr in dt.Rows)
                                    iletisim = new Iletisim(dr);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return iletisim;
        }

        public void Dispose()
        {
        }
    }
}
